package com.lvyq.service.impl;

import com.lvyq.model.receive.ReceiveMsg;
import com.lvyq.model.user.User;
import com.lvyq.repository.UserRepository;
import com.lvyq.service.ReceiveMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: weg
 * @description: 接收消息
 * @author: lvyq
 * @create: 2023-04-21 14:43
 **/
@Service
public class ReceiveMsgServiceImpl implements ReceiveMsgService {

    @Resource
    public UserRepository  userRepository;
    @Resource
    private MongoTemplate mongoTemplate;

    /** 
    * @Description: 保存用户发送信息
     * @param receiveMsg
    * @return: 
    * @Author: lvyq
    * @Date: 2023/4/21 15:06
    */
    
    @Override
    public void save(ReceiveMsg receiveMsg) {
        User user = userRepository.findByOpenId(receiveMsg.getFromUserName());
        receiveMsg.setSendUserName(user.getNickName());
        mongoTemplate.save(receiveMsg);
    }
}
